#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>

#define MYNAME  "mycdev"

int major;

int mycdev_open (struct inode *inode, struct file *file)
{
    printk("%s:%s:%d\n", __FILE__, __func__,__LINE__);
    return 0;
}
ssize_t mycdev_read (struct file *file, char __user *ubuf, size_t size, loff_t *offset)
{
    printk("%s:%s:%d\n", __FILE__, __func__,__LINE__);
    return 0;
}
ssize_t mycdev_write (struct file *file, const char __user *ubuf, size_t size, loff_t *offset)
{
    printk("%s:%s:%d\n", __FILE__, __func__,__LINE__);
    return 0;
}
int mycdev_close (struct inode *inode, struct file *file)
{
    printk("%s:%s:%d\n", __FILE__, __func__,__LINE__);
    return 0;
}

struct file_operations fops = {
    .open = mycdev_open,
    .read = mycdev_read,
    .write = mycdev_write,
    .release = mycdev_close,
};
static int __init mycdev_init(void)
{
    // 注册字符设备
    major = register_chrdev(0, MYNAME, &fops);
    if (major < 0) {
        printk("register char device failed!\n");
        return -EIO;
    }
    return 0;
}

static void __exit mycdev_exit(void)
{
    unregister_chrdev(major, MYNAME);
}
module_init(mycdev_init);
module_exit(mycdev_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("zk <zhouk_bj@hqyj.com>");